package service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import car.beans.CarInfo;
import factory.DBConnectFactory;

public class QueryServiceImpl implements QueryServiceInter
{
	Connection conn = null;
	
	public QueryServiceImpl(String type)
	{
		conn = DBConnectFactory.createDBConnect(type);
	}

	@Override
	public List<CarInfo> selectById(String id, String col)
	{
		// TODO Auto-generated method stub
		List<CarInfo> stulist = new ArrayList<>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try
		{
			ps = conn.prepareStatement("select * from car where " + col + " = " + id);
			rs = ps.executeQuery();
			while(rs.next())
			{
				CarInfo ci = new CarInfo(rs.getString(1),
						rs.getString(2),
						rs.getString(4),
						rs.getString(3));
				stulist.add(ci);
			}
			
		} catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return stulist;
	}

}
